﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;
using Pout_Porri.Screens.Interface;
using Pout_Porri.Objects;
using Pout_Porri.Utils;
using Pout_Porri.Levels;

namespace Pout_Porri.Screens
{
    class MegamanScreen : Screen, IScreen
    {
        private GameWindow gameWindow;
        private Level level;
        private Link link;
        private YellowDemon boss;

        // Atenção: Ao término da fase, classificar a boleana abaixo chamada de levelEnd como verdadeira, 
        // assim, a função Change Level no final da classe será acionada.
        private bool levelEnd;
        public bool LevelEnd
        {
            get { return levelEnd; }
            set { LevelEnd = value; }
        }

        public MegamanScreen(Texture2D background, GameWindow gameWindow) : base(background)
        {
            this.gameWindow = gameWindow;
        }

        public override void load(ContentManager content)
        {
            level = new Level(2, new Vector2(GameConfig.GAME_WIDTH, GameConfig.GAME_HEIGHT), content, background);

            Texture2D linkImg = content.Load<Texture2D>("Images\\Link\\LinkSpriteSheet");
            Texture2D swordImg = content.Load<Texture2D>("Images\\Link\\SwordSpriteSheet");
            Texture2D bossImg = content.Load<Texture2D>("Images\\Link\\YellowDemonSpriteSheet");

            link = new Link(linkImg, new Vector2(200, 400), new Vector2(3, 1), swordImg);
            link.Mass = 1f;
            link.AccelerationX = 0.02f;
            link.MaxVelocityX = 5;
            level.setPlayer(link);

            // comentando até funcionar corretamente
            //boss = new YellowDemon(bossImg, new Vector2(800, 10));
            level.addGameEntity(boss);

            Tileset tileset = new Tileset(88, 8, 0);
            tileset.loadTexture("Images\\Scene\\megaman_spritesheet", content);
            tileset.setEmptyTile(1, 40);
            level.setTileset(tileset);
        }

        public override void update(GameTime gameTime, GameWindow Window)
        {
            level.update(gameTime, Game1.keyboardState);
        }

        public override void draw(SpriteBatch spriteBatch)
        {
            level.draw(spriteBatch);
        }

        /*private void ChangeLevel()
        {
            if(LevelEnd)
            {
                ScreenManager.currentScreen = gameScreen;
            }
        }*/
    }
}
